cmake_minimum_required(VERSION 3.12)
project(plutosdr_sdr_support)


find_library(IIO_LIBRARY iio)
find_library(AD9361_LIBRARY ad9361)

if((IIO_LIBRARY AND AD9361_LIBRARY) OR MSVC OR ANDROID)
    message("Building with PlutoSDR support")
    file(GLOB_RECURSE plutosdr_sdr_support_CPPS *.cpp)
    add_library(plutosdr_sdr_support SHARED ${plutosdr_sdr_support_CPPS})
    target_include_directories(plutosdr_sdr_support PUBLIC src)

    if(MSVC)
        target_link_libraries(plutosdr_sdr_support PUBLIC satdump_core libiio.dll libad9361.dll)
        install(TARGETS plutosdr_sdr_support DESTINATION ${CMAKE_INSTALL_LIBDIR}/satdump/plugins RUNTIME_DEPENDENCY_SET satdump_deps)
    elseif(ANDROID)
        target_link_libraries(plutosdr_sdr_support PUBLIC satdump_core iio ad9361iio)
        target_include_directories(plutosdr_sdr_support PUBLIC ../../../android/deps/libiio ../../../android/deps/libad9361-iio)
        install(TARGETS plutosdr_sdr_support DESTINATION ${CMAKE_INSTALL_LIBDIR}/satdump/plugins)
    else()
        target_link_libraries(plutosdr_sdr_support PUBLIC satdump_core ${IIO_LIBRARY} ${AD9361_LIBRARY})
        install(TARGETS plutosdr_sdr_support DESTINATION ${CMAKE_INSTALL_LIBDIR}/satdump/plugins)
    endif()
else()
    message("IIO or AD9361 Library could not be found! Not building.")
endif()